import java.awt.Graphics;
import java.awt.Point;


public class Rectangle {

	public int x;
	public int y;
	public int size;
	
	
	public Rectangle(Point p,int s){
		this.x=p.x;
		this.y=p.y;
		this.size=s;
		
	}//constructor

	public Rectangle(Rectangle r){
		this.x=r.x;
		this.y=r.y;
		this.size=r.size;
	}
	
	public Rectangle(int x, int y, int s){
		this.x=x;
		this.y=y;
		this.size=s;
	}
	
	public void setPosition(Point p){
		this.x=p.x-size/2;
		this.y=p.y-size/2;
		//this.x
	}
	
	public Point getPosition(){
		return new Point(x,y);
	}
	/*
	 * other Methods
	 */
	
	public Point getMidPoint(){
		return new Point(x+(size/2),y+(size/2));
	}
	
	public int getMidPointX(){
		return (x+size/2);
	}
	
	public int getMidPointY(){
		return (y+size/2);
	}
	
	public void drawPreviewPosition(Graphics g){
		g.fillRect(x,y, size, size);
	}
	/*
	 * returns true if the rectangle interlapses with the 
	 * rectangle of parameter rect
	 */
	public boolean interlapse(Rectangle rect){
	 
		return (testPoint(rect.x, rect.y)
				|| testPoint(rect.x+rect.size,rect.y)
				|| testPoint(rect.x, rect.y+rect.size)
				|| testPoint(rect.x+rect.size, rect.y+rect.size));
		
	}
	
	private boolean testPoint(int a, int b){
		if(a >=this.x && a <=x+size
				&& b >=this.y && b<=y+size){
			System.out.println(a+" "+b);
			System.out.println(x+" "+y+"   "+(x+size)+" "+(y+size));
			return true;
		}
		return false;
	}
	
	public boolean isOutOfBounds(int w, int h){
		if(this.x<0 || x+size > w || y<0 || y+size>h){
			return true;
		}
		return false;
		
	}//isOutOfBounds(int w, int h)
	
	
	public boolean isAtBorder(int a, int b){
		if((a>=this.x && a<=this.x+size)&&
				b>=this.y && b<this.y+size){
			return true;
		}
		return false;
	}
}//class
